package com.tj.test.sys.service.impl;

import com.tj.test.sys.dao.StudentMapper;
import com.tj.test.sys.po.PST;
import com.tj.test.sys.po.Student;
import com.tj.test.sys.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class StudentService implements IStudentService {
    @Autowired
    private StudentMapper mapper;

    @Override
    //查询所有学生信息
    public List<Student> selectAllStudent() {
        List<Student> list=new ArrayList<>();
        if (!mapper.selectAllStudent().isEmpty()){
            list=mapper.selectAllStudent();
        }
        return list;
    }

    @Override
    //插入学生信息
    public int insertStudent(PST student) {
        int temp=0;
        /* 业务判断
         * （1）人员名称不能重复
         * （2）增加人员之前先查询*/
        try{
            //temp=mapper.selectStudentById(student);
            if (temp<1){
                //temp=mapper.insertStudent(student);
            }else{
                return temp;
            }
        }catch (Exception e){
            return -2;
        }
        return temp;
    }

    @Override
    //删除学生信息
    public int deleteStudent(PST student)   {
        int temp=0;
        try{
            temp=mapper.selectStudentById(student);
            if (temp>0){
                temp=mapper.deleteStudent(student);
            }else{
                return -2;
            }
        }catch (Exception e){
            return -1;
        }
        return temp;
    }

    @Override
    //修改学生信息
    public int updateStudent(PST student) {
        int temp=0;
        try{
            temp=mapper.selectStudentById(student);
            if (temp>0){
                temp=mapper.updateStudent(student);
            }else{
                return temp;
            }
        }catch (Exception e){
            System.out.println(e.getStackTrace());
            return -1;
        }
        return temp;
    }
}
